<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('维修保养记录列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>计划编号：</label>
                            <input type="text" name="planId"/>
                        </li>
                        <li>
                            <label>资产编号：</label>
                            <input type="text" name="assetNumber"/>
                        </li>
                        <li>
                            <label>申请人：</label>
                            <input type="text" name="applicant"/>
                        </li>
                        <li>
                            <label>维修状态：</label>
                            <select name="maintenanceType" th:with="type=${@dict.getType('maintenance_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>记录日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginRecordDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endRecordDate]"/>
                        </li>
                        <li class="select-time">
                            <label>维修日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginMaintenanceDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endMaintenanceDate]"/>
                        </li>
                        <li>
                            <label>维修费用：</label>
                            <input type="text" name="maintenanceCost"/>
                        </li>
                        <li>
                            <label>维修人员：</label>
                            <input type="text" name="maintenancePersonnel"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="asset:maintenanceRecord:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="asset:maintenanceRecord:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.cancel()"-->
            <a class="btn btn-danger multiple disabled" onclick="cancel()"
               shiro:hasPermission="asset:maintenanceRecord:cancel">
                <i class="fa fa-remove"></i> 取消
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="asset:maintenanceRecord:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('asset:maintenanceRecord:edit')}]];
    var cancelFlag = [[${@permission.hasPermi('asset:maintenanceRecord:cancel')}]];
    var maintenanceTypeData = [[${@dict.getType('maintenance_type')}]];
    var maintenanceContentData = [[${@dict.getType('maintenance_content')}]];
    var prefix = ctx + "asset/maintenanceRecord";

    function cancel() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        $.modal.confirm("确认要取消选中的" + rows.length + "条数据吗?", function () {
            $.ajax({
                url:"/asset/maintenanceRecord/cancel",
                type:"POST",
                data:{"ids": rows.join()},
                success: function (response) {
                    if (response.code == 0) {
                        $.modal.msgSuccess("取消成功！",modal_status.SUCCESS);
                        location.reload();
                    } else {
                        $.modal.msgError(response.msg)
                    }
                }
            })
        })
        };


  /*  function printById(data) {
        $.ajax({
            url: "/asset/maintenanceRecord/cancel", // 替换/backend-url为你的后端接口URL
            type: "POST",
            data: data, // 替换为你要发送的数据字段名和对应的值
            success: function (response) {
                console.log(response)
                if (response.code == 200) {
                } else {
                    $.modal.msgError(response.msg)
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                console.error("请求失败：" + xhr.status);
                console.error("异常信息：" + xhr.responseText); // 异常信息在响应的responseText中
            }
        });
    }*/

/*
    function cancel() {
        table.set();
        var data;
        // var data = {"ids": rows.join()};
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        $.modal.confirm("确认要取消选中的" + rows.length + "条数据吗?", function () {
                var data = {"ids": rows.join()};

                printById(data)

            },
        );
        /!*  $.post("/asset/maintenanceRecord/cancel", data), function (response) {
              console.log(response);
              if (response.code == 0) {
                  // 将后端返回的参数设置给使用人输入框
                  console.log("ssddfs")
                  alert("已取消！")
              } else {
                  console.log("slldjjl")
                  alert(response.msg);
              }
          }*!/
    };*/

    function cancelById(id) {
        // 发送GET请求到后端获取参数
        $.post("/asset/maintenanceRecord/cancelById", {id: id}, function (response) {
            if (response.code == 0) {
                // 将后端返回的参数设置给使用人输入框
                alert("已取消！")
            } else {
                alert(response.msg);
            }
        });
    };
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            // removeUrl: prefix + "/cancel",
            cancelUrl: prefix + "/cancel",
            exportUrl: prefix + "/export",
            modalName: "维修保养记录",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '记录编号',
                    visible: false
                },
                {
                    field: 'planId',
                    title: '计划编号'
                },
                {
                    field: 'assetNumber',
                    title: '资产编号'
                },
                {
                    field: 'recordDate',
                    title: '记录日期'
                },
                {
                    field: 'applicant',
                    title: '申请人'
                },
                {
                    field: 'applicantName',
                    title: '申请人姓名'
                },
                {
                    field: 'maintenanceType',
                    title: '维修类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(maintenanceTypeData, value);
                    }
                },
                {
                    field: 'maintenanceDate',
                    title: '维修日期'
                },
                {
                    field: 'maintenanceContent',
                    title: '维修内容',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(maintenanceContentData, value);
                    }
                },
                {
                    field: 'maintenanceCost',
                    title: '维修费用'
                },
                {
                    field: 'maintenancePersonnel',
                    title: '维修人员'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="$.operate.cancelById(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="cancelById(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>